route_head* route_head_alloc(void);
void route_add(waypoint*);
void route_add_wpt(route_head* rte, waypoint* wpt);
+void route_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits);
void route_del_wpt(route_head* rte, waypoint* wpt);
void track_add_wpt(route_head* rte, waypoint* wpt);
+void track_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits);
void track_del_wpt(route_head* rte, waypoint* wpt);
void route_add_head(route_head* rte);
void route_del_head(route_head* rte);
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<gpx version="1.1" creator="GPSBabel - http://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/1">\r
+ <metadata>\r
+ <time>1970-01-01T00:00:00Z</time>\r
+ <bounds minlat="47.421095000" minlon="19.220695000" maxlat="47.421186000" maxlon="19.220939000"/>\r
+ </metadata>\r
+ <rte>\r
+ <rtept lat="47.421186000" lon="19.220939000">\r
+ <ele>152.000000</ele>\r
+ <time>2012-11-05T07:16:29Z</time>\r
+ <name>RPT01</name>\r
+ <hdop>2.000000</hdop>\r
+ </rtept>\r
+ </rte>\r
+ <rte>\r
+ <rtept lat="47.421095000" lon="19.220695000">\r
+ <ele>138.300000</ele>\r
+ <time>2012-11-05T07:17:37Z</time>\r
+ <name>RPT02</name>\r
+ <hdop>3.000000</hdop>\r
+ </rtept>\r
+ </rte>\r
+ <rte>\r
+ <name>Name Track</name>\r
+ <desc>Generated from track Name Track</desc>\r
+ <rtept lat="47.421186000" lon="19.220939000">\r
+ <ele>152.000000</ele>\r
+ <time>2012-11-05T07:16:29Z</time>\r
+ <name>Name Track03</name>\r
+ <hdop>2.000000</hdop>\r
+ </rtept>\r
+ </rte>\r
+ <rte>\r
+ <name>Name Track #2</name>\r
+ <desc>Generated from track Name Track #2</desc>\r
+ <rtept lat="47.421095000" lon="19.220695000">\r
+ <ele>138.300000</ele>\r
+ <time>2012-11-05T07:17:37Z</time>\r
+ <name>Name Track #204</name>\r
+ <hdop>3.000000</hdop>\r
+ </rtept>\r
+ </rte>\r
+</gpx>\r
}
static void
-any_route_add_wpt(route_head* rte, waypoint* wpt, int* ct, int synth)
+any_route_add_wpt(route_head* rte, waypoint* wpt, int* ct, int synth, const char* namepart, int number_digits)
{
ENQUEUE_TAIL(&rte->waypoint_list, &wpt->Q);
rte->rte_waypt_ct++; /* waypoints in this route */
(*ct)++;
}
if (synth && !wpt->shortname) {
- char tmpnam[10];
- snprintf(tmpnam, sizeof(tmpnam), "RPT%03d",*ct);
- wpt->shortname = xstrdup(tmpnam);
+ xasprintf(&wpt->shortname,"%s%0*d", namepart, number_digits, *ct);
wpt->wpt_flags.shortname_is_synthetic = 1;
}
update_common_traits(wpt);
}
void
-route_add_wpt(route_head* rte, waypoint* wpt)
+route_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits)
{
// First point in a route is always a new segment.
// This improves compatibility when reading from
wpt->wpt_flags.new_trkseg = 1;
}
- any_route_add_wpt(rte, wpt, &rte_waypts, 1);
+ any_route_add_wpt(rte, wpt, &rte_waypts, 1, namepart, number_digits);
}
void
-track_add_wpt(route_head* rte, waypoint* wpt)
+route_add_wpt(route_head* rte, waypoint* wpt)
+{
+ const char RPT[] = "RPT";
+ route_add_wpt_named(rte, wpt, RPT, 3);
+}
+
+void
+track_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits)
{
// First point in a track is always a new segment.
// This improves compatibility when reading from
wpt->wpt_flags.new_trkseg = 1;
}
- any_route_add_wpt(rte, wpt, &trk_waypts, 0);
+ any_route_add_wpt(rte, wpt, &trk_waypts, 0, namepart, number_digits);
+}
+
+void
+track_add_wpt(route_head* rte, waypoint* wpt)
+{
+ const char RPT[] = "RPT";
+ track_add_wpt_named(rte, wpt, RPT, 3);
}
waypoint*
*dst_count = 0;
*dst_wpt_count = 0;
}
+
+ const char RPT[] = "RPT";
QUEUE_FOR_EACH(src, elem, tmp) {
route_head* rte_old = (route_head*)elem;
rte_new->rte_num = rte_old->rte_num;
any_route_add_head(rte_new, *dst);
QUEUE_FOR_EACH(&rte_old->waypoint_list, elem2, tmp2) {
- any_route_add_wpt(rte_new, waypt_dupe((waypoint*)elem2), dst_wpt_count, 0);
+ any_route_add_wpt(rte_new, waypt_dupe((waypoint*)elem2), dst_wpt_count, 0, RPT, 3);
}
(*dst_count)++;
}
gpsbabel -i gpx -f ${REFERENCE}/expertgps.gpx -x nuketypes,waypoints,tracks -x transform,wpt=rte,del=y -o gpx,gpxver=1.1 -F ${TMPDIR}/transform-wpt.gpx
compare ${REFERENCE}/transform-wpt.gpx ${TMPDIR}/transform-wpt.gpx
+rm -f ${TMPDIR}/transform-names.gpx
+gpsbabel -t -i gpx -f ${REFERENCE}/track/seg2trk_test-seg.gpx -x nuketypes,routes,waypoints -x transform,rte=trk,del=y,rptname=y,rptdigits=2 -o gpx,gpxver=1.1 -F ${TMPDIR}/transform-names.gpx
+compare ${REFERENCE}/transform-names.gpx ${TMPDIR}/transform-names.gpx
static route_head* current_trk;
static route_head* current_rte;
-static char* opt_routes, *opt_tracks, *opt_waypts, *opt_delete;
+static char* opt_routes, *opt_tracks, *opt_waypts, *opt_delete, *rpt_name_digits, *opt_rpt_name;
+
+static char* current_namepart;
+
+static int name_digits, use_src_name;
+
+static char RPT[] = "RPT";
static
arglist_t transform_args[] = {
"trk", &opt_tracks, "Transform waypoint(s) or route(s) into tracks(s) [W/R]", NULL,
ARGTYPE_STRING, ARG_NOMINMAX
},
+ {
+ "rptdigits", &rpt_name_digits, "Number of digits in generated names", NULL,
+ ARGTYPE_INT, "2", NULL
+ },
+ {
+ "rptname", &opt_rpt_name, "Use source name for route point names", "N",
+ ARGTYPE_BOOL, ARG_NOMINMAX
+ },
{
"del", &opt_delete, "Delete source data after transformation", "N",
ARGTYPE_BOOL, ARG_NOMINMAX
wpt = waypt_dupe(wpt);
switch (current_target) {
case 'R':
- route_add_wpt(rte, wpt);
+ route_add_wpt_named(rte, wpt, RPT, name_digits);
break;
case 'T':
- track_add_wpt(rte, wpt);
+ track_add_wpt_named(rte, wpt, RPT, name_digits);
break;
}
}
static void
transform_rte_disp_hdr_cb(const route_head* rte)
{
+ current_namepart = RPT;
+ if (rte->rte_name && *rte->rte_name && use_src_name) {
+ current_namepart = rte->rte_name;
+ }
if (current_target == 'T') {
current_trk = route_head_alloc();
track_add_head(current_trk);
static void
transform_trk_disp_hdr_cb(const route_head* trk)
{
+ current_namepart = RPT;
+ if (trk->rte_name && *trk->rte_name && use_src_name) {
+ current_namepart = trk->rte_name;
+ }
if (current_target == 'R') {
current_rte = route_head_alloc();
route_add_head(current_rte);
{
waypoint* temp = waypt_dupe(wpt);
if (current_target == 'R') {
- route_add_wpt(current_rte, temp);
+ route_add_wpt_named(current_rte, temp, current_namepart, name_digits);
} else if (current_target == 'T') {
- track_add_wpt(current_trk, temp);
+ track_add_wpt_named(current_trk, temp, current_namepart, name_digits);
} else {
waypt_add(temp);
}
{
int delete_after = (opt_delete && (*opt_delete == '1')) ? 1 : 0;
+ use_src_name = (opt_rpt_name && (*opt_rpt_name == '1')) ? 1 : 0;
+
+ name_digits = 3;
+ if (rpt_name_digits && *rpt_name_digits) {
+ name_digits = atoi(rpt_name_digits);
+ }
+
if (opt_waypts != NULL) {
current_target = 'W';
switch (toupper(*opt_waypts)) {
--- /dev/null
+<para>\r
+This option lets you configure how many digits GPSBabel uses for numbering generated route point names.\r
+</para>\r
+<para>\r
+When GPSBabel creates route points during the transformation process these points are sequentially numbered and named "RPTxxx" where xxx represent the number. By default GPSBabel uses 3 digits for these numbers. Rationale: This way a large number of route points can be uniquely named while the generated names are limited to 6 characters. This limitation is imposed by specific GPS devices.\r
+</para>\r
+<para>\r
+Using this option GPSBabel can be configured to use less or more digits for the generated names. This option is best used in conjunction with the rptname option.\r
+</para>\r
+<example id="transform_rptdigits">\r
+<title>Convert a GPX track to a GPX route, deleting the original track, using 2 digits for the generated numbers.</title>\r
+<para><userinput>gpsbabel -i gpx -f track.gpx -x transform,wpt=trk,del,rptdigits=2 -o gpx -F route.gpx</userinput></para>\r
+</example>\r
--- /dev/null
+<para>\r
+With this option you can decide to let GPSBabel name generated route points according to their source track name.\r
+</para>\r
+<para>\r
+GPSBabel creates route points during the transformation process named "RPTxxx" where xxx is a numeric part.</para>\r
+<para>\r
+Using this option GPSBabel can be configured to replace the "RPT" part of the generated names by the name of the source track during the transformation process. This is especially usefull if several differently named tracks are contained in the source file which should each be transformed into routes.\r
+</para>\r
+<example id="transform_rptname">\r
+<title>Convert a GPX track to a GPX route, deleting the original track, naming the generated points like the original track name.</title>\r
+<para><userinput>gpsbabel -i gpx -f track.gpx -x transform,wpt=trk,del,rptname=y -o gpx -F route.gpx</userinput></para>\r
+</example>\r